package com.example.demo;

import com.example.demo.kafka.entity.User;
import com.example.demo.kafka.service.KafkaProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@SpringBootApplication
@EnableScheduling
public class DemoApplication {
	@Autowired
	private KafkaProviderService kafkaProviderService;
	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
	//然后每隔1分钟执行一次
	@Scheduled(fixedRate = 5000)
	public void testKafka() throws Exception {
		User user = new User();
		/*for (int i=0;i<10;i++) {
			kafkaProviderService.send("myTopics2", user);
		}*/
		kafkaProviderService.send("myTopics2",user);
	}
}
